<?php

abstract class base_abstract
{
    function __construct()
    {
        if (isset($_POST["PHPSESSID"])) {
            session_id($_POST["PHPSESSID"]);
        }

		if (IS_SINA) {
			include_once 'Session.php';
			Session::session_start('memcache', array('vfsbak' => 'true'));
		} else {
			session_start();
		}

        if (IS_SINA) {
		    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
            header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        }

        $this->smarty = Smarty3::instance();
        $this->smarty->setTemplateDir(ROOT_PATH.'/Template');
        $this->smarty->compile_dir = Config::get('compile_dir');
        $this->smarty->error_reporting = E_ALL ^ E_NOTICE;
        $this->smarty->assign('config_site_url', Config::get('domainname'));
        $this->api = new ApiSina();
    }
    
    function isPost()
    {
        return 'POST' == @$_SERVER['REQUEST_METHOD'];
    }

    function msg($msg, $jumpurl='') {
       if ($jumpurl) {
            $jumpurl = htmlspecialchars($jumpurl);
            if (substr($jumpurl, 0, 4) != 'http') {
                if ($jumpurl{0} != '/') {
                    $jumpurl = '/'.$jumpurl;
                }
                $jumpurl = SITE_URL.$jumpurl;
            }
            $ifjump = "<META HTTP-EQUIV='Refresh' CONTENT='3; URL=$jumpurl'>";
            $this->smarty->assign('jumpurl', $jumpurl);
            $this->smarty->assign('ifjump', $ifjump);
        }

        $this->smarty->assign('msg', $msg);
        $this->smarty->display('msg.html');
        exit;
    }

    function redirect($url = '')
    {
        $site = SITE_URL;
        if (!$url) {
            $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : (!empty($_SESSION['LAST_URL']) ? $_SESSION['LAST_URL'] : $site);
        }

        if (substr($url, 0, 4) != 'http') {
            if ($url{0} != '/') {
                $url = '/'.$url;
            }
            $url = $site.$url;
        }
        header('Location: ' . $url);
        exit;
    }
}

?>